package cn.hughie.imooc.singelton;

/**
 * @Author yuh
 * @Date Created in 下午12:31 2018/5/26
 * @Description 枚举类的构造全局只执行一次  上面的枚举全是枚举对象 这些枚举对象都是全局单例的
 */
public class Demo {

    private Demo() {
    }

    public static Demo getInstance() {
        System.out.println(Holder.A.hashCode());
        System.out.println(Holder.B.hashCode());
        return Holder.D.getInstance();
    }


    private enum Holder {
        A, B, C, D;

        private Demo instance = null;

        Holder() {
            instance = new Demo();
        }

        public Demo getInstance() {
            return instance;
        }


    }

    public static void main(String[] args) {
        Demo instance = Demo.getInstance();
        System.out.println("A".hashCode());
    }

}
